@extends('layouts.admin')
@section('content')
    <!--面包屑导航 开始-->
    <div class="crumb_warp">
        <!--<i class="fa fa-bell"></i> 欢迎使用登陆网站后台，建站的首选工具。-->
        <i class="fa fa-home"></i> <a href="{{ url('admin/info') }}">首页</a> &raquo; 文章列表
    </div>
    <!--面包屑导航 结束-->

    <!--搜索结果页面 列表 开始-->
    <form action="#" method="post">
        <div class="result_wrap">
            <!--快捷导航 开始-->
            <div class="result_content">
                <div class="result_title">
                    <h3>文章管理操作</h3>
                </div>
                <div class="short_wrap">
                    <a href="{{url('admin/article/create')}}"><i class="fa fa-plus"></i>添加文章</a>
                    <a href="{{url('admin/article')}}"><i class="fa fa-recycle"></i>文章列表</a>
                </div>
            </div>
            <!--快捷导航 结束-->
        </div>

        <div class="result_wrap">
            <div class="result_content">
                <table class="list_tab">
                    <tr>
                        <th class="tc">排序</th>
                        <th class="tc">ID</th>
                        <th>分类</th>
                        <th>标题</th>
                        <th>描述</th>
                        <th>查看次数</th>
                        <th>操作</th>
                    </tr>

                    @foreach($data as $v)
                    <tr>
                        <td class="tc">
                            <input type="text" onchange="changeOrder(this, {{ $v->art_id }});" name="ord[]" value="{{ $v->art_order }}">
                        </td>
                        <td class="tc">{{ $v->art_id }}</td>
                        <td>@if(isset($v->ext_cate->cate_name)){{ $v->ext_cate->cate_name }}@endif</td>
                        <td>
                            <a href="#">{{ $v->art_title }}</a>
                        </td>
                        <td>{{ mb_substr($v->art_description,0,20)}}</td>
                        <td>{{ $v->art_view }}</td>
                        <td>
                            <a href="{{ url('admin/article/'. $v->art_id . '/edit') }}">修改</a>
                            <a href="javascript:;" onclick="del_art('{{ $v->art_id }}')">删除</a>
                        </td>
                    </tr>
                    @endforeach

                </table>

                <div class="page_nav">
                    <div>
                        {{ $data->links() }}
                    </div>
                </div>
                <style type="text/css">
                    .result_content ul li span {
                        font-size: 15px;
                        padding: 6px 12px;
                    }
                </style>

            </div>
        </div>
    </form>
    <!--搜索结果页面 列表 结束-->
    <script>
        function changeOrder(obj, art_id) {
            var art_order = $(obj).val();
            $.post('{{url('admin/change_order')}}',{'_token':'{{csrf_token()}}','id':art_id,'order':art_order,'type':'article'}, function (data) {
                layer.msg(data.msg);
            })
        }

        function del_art(art_id) {
            //询问框
            layer.confirm('您确定要删除这篇文章吗？', {
                btn: ['确定','取消'] //按钮
            }, function(){
                //发送post请求
                $.post('{{url('admin/article/')}}/' + art_id, {_method:'DELETE','_token':'{{csrf_token()}}'}, function (data) {
                    if(data.errno) {
                        layer.msg(data.msg, {icon: 2});
                    }else {
                        layer.msg('删除成功', {icon: 1});
                        location.href=location.href;
                    }
                })
            }, function(){
                //layer.msg('11', {icon: 2});
            });
        }
    </script>

@endsection